﻿using System;
using Microsoft.Extensions.DependencyInjection;

namespace Best.SmartCms.Core.Extension
{
    /// <summary>
    /// Ioc 容器服务.
    /// </summary>
    public static class ServiceProviderExtentions
    {
        private static ServiceProvider _serviceProvider;

        /// <summary>
        /// SetServiceProvider.
        /// </summary>
        /// <param name="serviceCollection">serviceCollection</param>
        public static void SetServiceProvider(IServiceCollection serviceCollection)
        {
            _serviceProvider = serviceCollection.BuildServiceProvider();
        }

        /// <summary>
        /// 获取服务
        /// </summary>
        public static T GetService<T>()
        {
            var svc = _serviceProvider.GetService<T>();
            return svc;
        }
    }
}
